<?php $this->load->view('headerfooter/header'); ?>

	<div class="container">
		<div class="col-sm-4">
			<!-- div style="margin-left:190px" -->
			<div class="col-sm-offset-3">
				<h4 class="alert alert-success text-center">
					<button type="button" class="close" data-dismiss="alert">&times;</button>
					Selamat datang, <?=$this->session->userdata('nama_lengkap');?> ! <a href="#"></a>
				</h4>
			</div>
			<!-- /div -->
			<div class="col-sm-offset-3">
				<div class="panel panel-success" style="width: 120%;margin-left: -11%;">
					<div class="panel-heading">
						<div class="panel-title text-center">
						<?php if($jumlah_notif != 0) : ?>
							Terdapat <?=$jumlah_notif?> surat mendekati masa kadaluwarsa.
						<?php else: ?>
							Notifikasi
						<?php endif; ?>
						</div>
					</div>
					<div class="panel-body">
						<div id="dashboard-notification">
							<!-- script id="result_template" type="text/x-handlebars-template" -->
								{{! only output if result exists }}
								                                
								 {{#if results}}
								    {{#each results}}
								        <div class="list-group-item">
								        	Surat dengan kode <strong>{{kode_surat}}</strong> terkait instansi <strong>{{nama_instansi}}</strong> akan kadaluarsa pada <strong>{{masa_berlaku}}</strong> <a href="<?=site_url('surat/view/')?>/{{idsurat}}" class="btn"><i class="fa fa-eye"></i> Lihat</a>
								        </div>
								    {{/each}}
								{{else}}
								    <h3>Tidak ada surat yang kadaluwarsa!=</h3>
								{{/if}}
		                    <!-- /script-->
						</div>
					<div class="text-right">
						<div id="pagination"></div>
					</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<script src="<?=base_url('src/js/handlebars-v1.3.0.js') ?>"></script>
	<script type="text/javascript">
		var site_url = "<?=site_url(); ?>";
		$(document).ready(function() {

			var source = $("#dashboard-notification").html();
			if (source) {

				var result_template = Handlebars.compile(source);

				function load_result(index) {
					index = index || 0;
					$.post(site_url + "/dashboard/notifikasi/" + index, {  ajax: true }, function(data) {
						$("#dashboard-notification").html(result_template({results: data.results}));
						// pagination
						$('#pagination').html(data.pagination);
					}, "json");
				}

				//calling the function 
				load_result();
			}


			//pagination update
			$('#pagination').on('click', '.pagination a', function(e) {
				console.log('klik');
				e.preventDefault();
				//grab the last paramter from url
				var link = $(this).attr("href").split(/\//g).pop();
				load_result(link);
				return false;
			});
		});
	</script>
                        
 <?php $this->load->view('headerfooter/footer'); ?>
